/*  This file is part of the comicconquer project
    Copyright (C) 2010 Reach <reach334@gmail.com>

    ComicConquer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with this software.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "GestureRecordDlg.h"

extern QDialog* g_mainDialog;

GestureRecordDlg::GestureRecordDlg(QWidget* parent) : QDialog(parent)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CO_MOUSEATTATCH;

    setFixedSize(g_mainDialog->size());
    setWindowFlags(Qt::FramelessWindowHint);
    m_gesture = 0;

    Out_Log(__FUNCTION__, COCLASSNAME);
}

int GestureRecordDlg::recordGesture(QWidget* parent)
{
    In_Log(__FUNCTION__);

    GestureRecordDlg dlg(parent); 
    if (dlg.exec() == Accepted)
    {

        Out_Log(__FUNCTION__);
        return dlg.m_gesture;
    }


    Out_Log(__FUNCTION__);
    return -1;
}

bool GestureRecordDlg::event(QEvent* e)
{
    bool ret = QDialog::event(e);

    switch (e->type())
    {
    case QEvent::UpdateRequest:
        onyx::screen::ScreenProxy::instance().flush(this, ScreenProxy::GC);
        return true;
        break;

    default:
        break;
    }

    return ret;
}

void GestureRecordDlg::mouseCtlEvent(GestureEvent* event)
{
    m_gesture = event->gesture & ((1<<30) - 1);
    accept();
}

